package com.project.restaurant.order.controller;


import com.project.restaurant.common.api.ResponseResult;
import com.project.restaurant.common.api.ServiceReturn;
import com.project.restaurant.common.api.ServiceStateCode;
import com.project.restaurant.order.dto.*;
import com.project.restaurant.order.enums.OrderState;
import com.project.restaurant.order.service.OrderService;
import com.project.restaurant.thirdpart.enums.WXPayState;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(value = "订单接口",tags = "订单接口")
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    //待修改
    @ApiOperation(value = "查看简洁订单列表",notes = "")
    @ApiResponse(code = 200, message = "操作成功", response = BriefOrderVo.class)
    @PostMapping(value = {"/look/briefOrder/{orderState}","/look/briefOrder"})
    public ResponseResult<BriefOrderVo> lookUserBriefOrder(@ApiParam(value = "订单状态;不传默认查看全部") @PathVariable(value = "orderState",required = false) OrderState orderState){
        BriefOrderVo result = orderService.obtainUserBriefOrder(orderState);
        return ResponseResult.success(result);
    }

    @ApiOperation(value = "查看详细订单信息",notes = "")
    @ApiResponse(code = 200, message = "操作成功", response = DetailOrderVo.class)
    @GetMapping(value = "/look/detailOrder/{orderId}")
    public ResponseResult<DetailOrderVo> lookUserDetailOrder(@PathVariable("orderId")String orderId){
        DetailOrderVo result = orderService.obtainUserDetailOrder(orderId);
        return ResponseResult.success(result);
    }

    @ApiOperation(value = "下单",notes = "")
    @ApiResponse(code = 200, message = "操作成功", response = QRPayInfo.class)
    @PostMapping(value = "/create")
    public ResponseResult<QRPayInfo> createOrder(@ApiParam(value = "下单信息",required = true) @RequestBody PlaceOrderInfo placeOrderInfo) throws Exception {
        QRPayInfo result = orderService.createOrder(placeOrderInfo);
        return ResponseResult.success(result);
    }

    @ApiOperation(value = "刷新支付二维码",notes = "返回支付二维码的base64编码字符串")
    @ApiResponse(code = 200, message = "操作成功", response = String.class)
    @GetMapping(value = "/flush/qrCode/{orderId}")
    public ResponseResult<String> flushQRCode(@ApiParam(value = "订单id",required = true) @PathVariable("orderId")String orderId){
        String result = orderService.flushQRCode(orderId);
        return ResponseResult.success(result);
    }

    @ApiOperation(value = "查看订单支付状态",notes = "返回订单支付状态")
    @ApiResponse(code = 200, message = "操作成功", response = WXPayState.class)
    @GetMapping(value = "/look/payState/{orderId}")
    public ResponseResult<WXPayState> lookPayState(@ApiParam(value = "订单id",required = true) @PathVariable("orderId")String orderId){
        WXPayState result = orderService.isWXPaySuccess(orderId);
        return ResponseResult.success(result);
    }

}
